home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
HENSA
/
MISC
/
SHELL.ARC
/
Shell
/
Sources
/
c
/
Label
< prev
next >
Wrap
Text File
|
1994-07-27
|
3KB
|
153 lines
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include "DeskLib:WimpSWIs.h"
#include "Shell.Shell.h"
#include "Shell.Extra.h"
#include "Shell.Check.h"
#include "Shell.SafeAlloc.h"
#include "Shell.Label.h"
static void Shell_LabelDisplayer(
Shell_convertpoint convert,
wimp_point rectsize,
void *reference,
const wimp_rect *redrawrect
)
{
char *text = (char *) reference;
UNUSED( redrawrect);
Shell_PrintString( text, 0, rectsize.y, convert);
return;
}
static BOOL Shell_LabelSaver( char *filename, Shell_rectblock *r)
{ FILE *f;
char *text = (char *) r->reference;
f = fopen( filename, "w");
if (!f) return FALSE;
fprintf( f, text);
fclose( f);
return TRUE;
}
Shell_rectblock *Shell_Label(
Shell_windblock *w,
int x, int y,
int forecol, int backcol,
const char *text
)
{
wimp_rect rect;
int len = strlen( text);
char *text2;
Shell_rectblock *r;
rect.min.x = x; rect.max.x = x + Shell_TEXTXSIZE*len;
rect.max.y = y; rect.min.y = y - Shell_TEXTYSIZE;
text2 = Shell_SafeMalloc( 1+len);
strcpy( text2, text);
r = Shell_AddRectangle( w, &rect, Shell_LabelDisplayer, (void *) text2);
Shell_MakeRectIcon( r, forecol, backcol, "R1");
r->saver = Shell_LabelSaver;
return r;
}
Shell_rectblock *Shell_Labelf(
Shell_windblock *w,
int x, int y,
int forecol, int backcol,
const char *fmt, ...
)
{
va_list args;
va_start( args, fmt);
vsprintf( Shell_string, fmt, args);
va_end( args);
return Shell_Label( w, x, y, forecol, backcol, Shell_string);
}
/*
#define MAX( a, b) (( (a) > (b) ) ? a : b )
*/
void Shell_ReLabel( Shell_rectblock *r, const char *text)
{
wimp_rect oldiconrect;
int newlen = strlen( text);
int oldsize = r->rect.max.x - r->rect.min.x;
int newsize;
oldiconrect = r->icon.workarearect;
r->reference = Shell_SafeRealloc( r->reference, 1 + newlen);
strcpy( (char *) r->reference, text);
r->rect.max.x = r->rect.min.x + Shell_TEXTXSIZE * newlen;
newsize = r->rect.max.x - r->rect.min.x;
if ( newsize != oldsize) {
/* Redraw whole icon if it has changed size. */
Shell_ResizeIconRect( r);
/* Recalculate the icon border. Also forces redraw if rect is visible */
if ( oldsize > newsize) {
/* Need to erase extra space from the old (larger) icon. */
window_redrawblock block;
block.window = r->window;
block.rect = oldiconrect;
block.rect.min.x = r->icon.workarearect.max.x;
Wimp_ForceRedraw( &block);
}
}
else Shell_ForceRectRedraw( r); /* Don't have to do this if the rect has changed size */
}
void Shell_ReLabelf( Shell_rectblock *r, const char *fmt, ...)
{ va_list args;
va_start( args, fmt);
vsprintf( Shell_string, fmt, args);
va_end( args);
Shell_ReLabel( r, Shell_string);
}
void Shell_ReLabelfSlow( Shell_rectblock *r, const char *fmt, ...)
{ va_list args;
clock_t t = clock();
if ( t - r->last_update >= r->update_time) {
r->last_update = t;
va_start( args, fmt);
vsprintf( Shell_string, fmt, args);
va_end( args);
Shell_ReLabel( r, Shell_string);
}
}